package com.puppy.config;

import com.puppy.interceptor.DemoInterceptor;
import com.puppy.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
// 配置类，@Configuration的元注解有@Component，可以直接用@Component,但是我们这里强调是配置类，所以用@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private DemoInterceptor demoInterceptor;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    //从写addInterceptors方法，将拦截器注册到spring容器中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(demoInterceptor).addPathPatterns("/**");
        // 注册拦截器，并设置拦截规则"/**"所有路径都拦截
//        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns("/emp/login");
    }
}
